//
//  HZAlertView.m
//  HZTC_YaDeArt
//
//  Created by zeroing on 17/4/7.
//  Copyright © 2017年 HZTC. All rights reserved.
//

#import "HZAlertView.h"
#import "NSString+NormalTool.h"

@interface HZAlertView()
@property (nonatomic, strong)UIView      *pPopView;
@property (nonatomic, strong)UITextView  *pTextContent;
@property (nonatomic, strong)UIButton    *pCloseBtn;
@property (nonatomic, assign)CGFloat      fContentH;
@end

@implementation HZAlertView
#pragma mark -
#pragma mark 生命周期
- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self p_commonInit];
        self.backgroundColor = kMYHexToRGB(0x808080, 0.5);
    }
    return self;
}
#pragma mark -
#pragma mark private
- (void)p_commonInit
{
    _pPopView = [UIView new];
    _pTextContent = [UITextView  new];
    _pTextContent.delegate = (id)self;
    _pTextContent.textColor = kGRAYColor;
    [_pTextContent setFont:[UIFont systemFontOfSize:13]];
    [_pTextContent setBackgroundColor:[UIColor clearColor]];
    
    _pPopView.layer.masksToBounds = YES;
    _pPopView.layer.cornerRadius = 10;
    
    _pPopView.backgroundColor = [UIColor whiteColor];
    
    [self addSubview:_pPopView];
    [_pPopView addSubview:_pTextContent];
    
    _pCloseBtn  = [UIButton new];
    [_pCloseBtn setTitle:@"阅读并关闭" forState:UIControlStateNormal];
    _pCloseBtn.backgroundColor = kMYHexToRGB(0xf15059, 1);
    _pCloseBtn.clipsToBounds=YES;
    _pCloseBtn.layer.cornerRadius=20;
    [_pCloseBtn addTarget:self action:@selector(closeBtnOnClick) forControlEvents:UIControlEventTouchUpInside];
    [_pPopView addSubview:_pCloseBtn];

    
    [self p_initConstraints];
    
    _pTextContent.text = @"出金时间为交易日上午9:30-11:30，下午13:00-15:00 \n\n出金提交成功后将与1个工作日到账，具体时间以银行到账时间为准。周末、法定节日日及银行系统升级期间除外\n\n出金前请核对自己的银行卡信息是否绑定正确，若因为用户的原因（卡号不正确，姓名与卡号不匹配，银行与卡号不匹配等）造成未到账，本网站不负任何法定责任。";
    _fContentH = [_pTextContent.text heightWithLimitedWidth:CGRectGetWidth(self.frame) withFont:[UIFont systemFontOfSize:13]];
}

- (void)p_initConstraints
{
    [_pPopView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.mas_equalTo(self);
        make.left.mas_equalTo(self).offset(40);
        make.right.mas_equalTo(self).offset(-40);
        make.top.mas_equalTo(120);
        make.bottom.mas_equalTo(-120);
    }];
    [_pTextContent mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(_pPopView).offset(20);
        make.left.mas_equalTo(_pPopView).offset(20);
        make.right.mas_equalTo(_pPopView).offset(-20);
        make.height.mas_equalTo(_pPopView).offset(-60);
    }];
    
    [_pCloseBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(_pPopView).offset(50);
        make.width.mas_equalTo(_pPopView).offset(-100);
        make.height.mas_equalTo(40);
        make.bottom.mas_equalTo(_pPopView).offset(-20);
    }];
}
-(void)closeBtnOnClick{
    self.hidden = YES;
}
@end
